package com.example.kafkastudy.producer;

import com.example.kafkastudy.pojo.Company;
import com.example.kafkastudy.serializer.CompanySerializer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;
import java.util.concurrent.ExecutionException;

/**
 * @Author: zhudawang
 * @Date: 2021/05/03/8:14 下午
 * @Description:
 */
public class ProducerCompany {
    public static final String brokerList = "123.56.141.6:9092";
    public static final String topic = "quickstart-events";
    public static final String groupId = "group.demo";

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Properties properties = new Properties();
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, CompanySerializer.class.getName());
        properties.put("bootstrap.servers", brokerList);
        KafkaProducer<String, Company> producer = new KafkaProducer<String, Company>(properties);
        Company company = Company.builder().name("hiddenkafka").address("China").build();
        ProducerRecord<String, Company> record = new ProducerRecord<>(topic, company);
        producer.send(record).get();
    }
}
